Base.sum(x::Base.Dates.CompoundPeriod) = sum(typeof(x.periods[end]).(x.periods))

@inline value(x::I) where I<:Integer = x
value(x::T) where T = x

function subsecond_string(x::Nanoseconds)
    y = abs(x)

    nanosecs = nanosecond(y)
    microsecs = microsecond(y)
    millisecs = millisecond(y)
    scs = second(y)
    mns = minute(y)
    hrs = hour(y)
    dys = day(y)

    nanos  = nanosecs  === zero(Int4Span) ? "" : threedigits(nanosecs)
    micros = microsecs === zero(Int4Span) ? "" : threedigits(microsecs)
    millis = millisecs === zero(Int4Span) ? "" : threedigits(millisecs)
    return string(millis, micros, nanos)
end

subsecond_string(x::Microseconds) = subsecond_string(Nanoseconds(x))
subsecond_string(x::Milliseconds) = subsecond_string(Nanoseconds(x))

for T in (:Seconds, :Minutes, :QuarterHours, :Hours, :Days, :Weeks, :Months, :Years, :Decades, :Centuries)
    @eval subsecond_string(x::$T) = ""
end


